package fran.pinggoogle;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PingAdapter extends BaseAdapter{
	Activity context;
	ArrayList<String> pingResults;
	
	public PingAdapter(Context context) {
		this.context = (Activity)context;
		pingResults = new ArrayList<String>(0);
	}

	public void addPingResult(String pingResult) {
		if (pingResult != null) {
			pingResults.add(pingResult);
		}
	}
	
	public void setPingResults(ArrayList<String> pingResults){
		this.pingResults = pingResults;
	}
	
	@Override
	public int getCount() {
		return pingResults.size();
	}
	@Override
	public Object getItem(int position) {
		return pingResults.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	private class PingHolder {
	       TextView pingResult;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		PingHolder holder = null;
	       String pingResult = (String) getItem(position);
	       LayoutInflater mInflater = (LayoutInflater) context
	               .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
	       if (convertView == null) {
	           convertView = mInflater.inflate(R.layout.item_ping, null);
	           holder = new PingHolder();
	           holder.pingResult = (TextView) convertView.findViewById(R.id.txtNombreCliente);
	           convertView.setTag(holder);
	       } else
	           holder = (PingHolder) convertView.getTag();
	       holder.pingResult.setText(pingResult);
	       return convertView;
	}
}
